var admin = {};

/**
 * 处理ajax返回数据之后的刷新操作
 */
admin.ajaxReload = function(obj,callback){
    if("undefined" == typeof(callback)){
        callback = "location.href = location.href";
    }else{
        callback = 'eval('+callback+')';
    }
    if(obj.status == 1){
        alert(obj.data);
        setTimeout(callback,0);
     }else{
        alert(obj.data);
    }
};
//模拟ts U函数
function U(url,params){
	var website = _ROOT_+'/index.php';
	url = url.split('/');
	if(url[0]=='' || url[0]=='@')
		url[0] = APPNAME;
	if (!url[1])
		url[1] = 'Index';
	website = website+'?m='+url[0]+'&a='+url[1];
	if(params){
		params = params.join('&');
		website = website + '&' + params;
	}
	return website;
}

function jump(url){
	turl = U(url);
	location.href = turl;
}

function changeYear(str,isstart)
{
    var pre = "start";
    if(isstart == false)
    {
        pre = "end";
    }
    var startMonth = $(pre + "Month").value;
    if(startMonth == "")
    {
        var e = $(pre + "Month");
        optionClear(e);
        return;
    }
    var n = MonHead[startMonth - 1];
    if(startMonth == 2  && IsPinYear($(pre + "Year").value))
    {
        n++;
    }
    writeDay(n,pre);
}
function changeMonth(str,isstart)
{
    var pre = "start";
    if(isstart == false)
    {
        pre = "end";
    }
    var year = $(pre + "Year").value;
    if(year == "")
    {
        var e = $(pre + "Day");
        optionClear(e);
        return;
    }
    var n = MonHead[str - 1];
    if(str == 2 && IsPinYear($(pre + "Year")))
    {
        n++;
    }
    writeDay(n,pre);
}

function dateStart()
{
    var defaultStartY = "2011";
    var defaultStartM = "1";
    var defaultStartD = "14";

    var defaultEndY = "2011";
    var defaultEndM = "2";
    var defaultEndD = "23";
    
    MonHead = [31,28,31,30,31,30,31,31,30,31,30,31];

    var prestr = new Array("#start","#end");
    for(var j=0; j<2; j++)
    {
        var pre = prestr[j];
        //start 年
        var y = new Date().getFullYear();
        if(pre == "start")
        {
            //start初始选中前第10天
            var i_index = 0;
            for(var i=(y-10); i<=y; i++)
            {
                $(pre+"Year").options.add(new Option(""+i+"",i));
                if(i == defaultStartY)
                {
                    $(pre+"Year").options[i_index].selected = true;
                }
                i_index++;
            }
            
        }
        else
        {
            var i_index =0;
            for(var i=(y-5); i<=y+5; i++)
            {
                $(pre+"Year").options.add(new Option(""+i+"",i));
                if(i == defaultEndY)
                {
                    $(pre+"Year").options[i_index].selected = true;
                }
                i_index++;
            }
        }
        //start月
        defaultM = (pre == "start" ? defaultStartM : defaultEndM)
        for(var i = 1; i < 13; i++)
        {
            $(pre + "Month").options.add(new Option(""+i+"",i));
            if(i == defaultM)
            {
                $(pre + "Month").options[i-1].selected = true;
            }
        }
        //start日
        var n = MonHead[$(pre + "Month").value];
        if(new Date().getMonth == 1  && IsPinYear($(pre + "Year").value))
        {
            n++;
        }
        defaultD = (pre == "start" ? defaultStartD : defaultEndD)
        writeDay(n,pre);
        $(pre + "Day").options[defaultD-1].selected = true;
    }
}
function writeDay(n,pre)
{
    var e = $(pre + "Day");
    optionClear(e);
    for (var i=1; i<(n+1); i++)
    {
        e.options.add(new Option(""+i+"",i));
    }
}
function IsPinYear(year)
{
    return (0 == year%4 && (year%100 != 0 || year % 4 == 0));
}

function optionClear(e)
{
    for(var i=e.options.length; i>=0; i--)
    {
        e.remove(i);
    }
}


$(document).ready(function(){
	$("#khtel").blur(function(){
		tel = $(this).val();
		$.post(U('index/check_tel'),{tel:tel},function(res){
			if(res.status){
				$(".tel_status").html('<font color=green><strong>可用</strong></font>');
			}else{
				$(".tel_status").html('<font color=red><strong>已存在</strong></font>');
				$(this).focus().select();
			}
		},'json');
	});
	$(".resume_submit").click(function(){
		$(".resume_form").submit();
	});
});
